//
//  WHTdsSelectVC.m
//  WHEasyBizLink
//
//  Created by hyf on 2024/12/9.
//

#import "WHTdsSelectVC.h"
#import "WHTdsModel.h"
#import "WHDialog.h"
#import "WHTdsSelectViewCell.h"

@interface WHTdsSelectVC ()

@end

@implementation WHTdsSelectVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    self.tableView.backgroundColor = tableBgLightgrayColor;
    self.title = @"服务平台";
}

- (void)loadDatas{
    [super loadDatas];
    [WHTdsModel getTDSInfoWithBlock:^(id  _Nonnull responseObject) {
        self.datas = [NSMutableArray arrayWithArray:responseObject];
    } FailureBlock:^(NSString * _Nonnull msg) {
        NSLog(@"WHTdsSelectVC----请求跟平台列表失败：%@",msg);
        [[WHDialog sharedManager] showHudErrorWithText:@"请求失败，请稍后重试！"];
    }];
//    NSArray *list = [WHTdsModel getTDSList];
//    if (list.count>0) {
//        self.datas = [NSMutableArray arrayWithArray:list];
//    }else{
//        [WHTdsModel getTDSInfoWithBlock:^(id  _Nonnull responseObject) {
//            self.datas = [NSMutableArray arrayWithArray:responseObject];
//        } FailureBlock:^(NSString * _Nonnull msg) {
//            NSLog(@"WHTdsSelectVC----请求跟平台列表失败：%@",msg);
//            [[WHDialog sharedManager] showHudErrorWithText:@"请求失败，请稍后重试！"];
//        }];
//    }
}

- (void)setupUI{
    [super setupUI];
    //一个简单的super setupUI = createTableView
    self.tableView.frame =CGRectMake(0,navHeight1,ScreenW,ScreenH-navHeight1);
}

#pragma mark - <tableViewDelegate>
- (UITableViewCell *)tableView:(UITableView *)tableView
         cellForRowAtIndexPath:(NSIndexPath *)indexPath{
   
    WHTdsSelectViewCell *cell = [WHTdsSelectViewCell
                                     createReuseIdentifier:@"WHTdsSelectViewCellID" WithTableView:tableView];
    cell.model = self.datas[indexPath.row];
    cell.clickBtnBlock = ^(WHTdsModel * _Nonnull model) {
        for (WHTdsModel *tmp in self.datas) {
            if ([tmp.id isEqualToString:model.id]) {
                tmp.isSel = YES;
            } else {
                tmp.isSel = NO;
            }
        }
        self.datas = self.datas;
        [[NSUserDefaults standardUserDefaults] setObject:model.id forKey:mSelTDSChildKey];
        
        // 1.创建通知
        NSNotification *notification = [NSNotification notificationWithName:NOT_NAME_TDSCHANGE object:nil userInfo:nil];
        //通过 通知中心 发送 通知
        [[NSNotificationCenter defaultCenter] postNotification:notification];
    };
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView
 heightForRowAtIndexPath:(NSIndexPath *)indexPath{

   // return [tableView cellHeightForIndexPath:indexPath model:self.datas[indexPath.row] keyPath:@"model" cellClass:[WHEnterpriseCompanyCell class] contentViewWidth:ScreenW];
    return 110;
}

-(void)tableView:(UITableView *)tableView
commitEditingStyle:(UITableViewCellEditingStyle)editingStyle
forRowAtIndexPath:(NSIndexPath *)indexPath
{
   
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    DebugLog(@"tableView = %ld",(long)indexPath.row);
}

@end
